﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Data;
using System.Text;

namespace MyWeb.Data
{
    public class UserController : SqlDataProvider
    {
        #region[User_Insert]
        public void User_Insert(UserInfo data)
        {
            using (SqlCommand cmd = new SqlCommand("sp_User_Insert", GetConnection()))
            {
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add(new SqlParameter("@Name", data.Name));
                cmd.Parameters.Add(new SqlParameter("@UserName", data.UserName));
                cmd.Parameters.Add(new SqlParameter("@PassWord", data.Password));
                cmd.Parameters.Add(new SqlParameter("@Rule", data.Rule));
                cmd.Parameters.Add(new SqlParameter("@Status", data.Status));
                cmd.ExecuteNonQuery();
            }
        }
        #endregion User_Insert(UserInfo data)
        #region[User_Update]
        public void User_Update(UserInfo data)
        {
            using (SqlCommand cmd = new SqlCommand("sp_User_Update", GetConnection()))
            {
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add(new SqlParameter("@ID", data.ID));
                cmd.Parameters.Add(new SqlParameter("@Name", data.Name));
                cmd.Parameters.Add(new SqlParameter("@UserName", data.UserName));
                cmd.Parameters.Add(new SqlParameter("@PassWord", data.Password));
                cmd.Parameters.Add(new SqlParameter("@Rule", data.Rule));
                cmd.Parameters.Add(new SqlParameter("@Status", data.Status));
                cmd.ExecuteNonQuery();
            }
        }
        #endregion User_Insert(UserInfo data)
        #region[User_Delete]
        public void User_Delete(string ID)
        {
            using (SqlCommand cmd = new SqlCommand("sp_User_Delete", GetConnection()))
            {
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add(new SqlParameter("@ID",ID));

                cmd.ExecuteNonQuery();
            }
        }
        #endregion User_Insert(UserInfo data)
        #region[User_GetByAll]
        public DataTable User_GetByAll()
        {
            using (SqlCommand cmd = new SqlCommand("sp_User_GetByAll", GetConnection()))
            {
                cmd.CommandType = CommandType.StoredProcedure;
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                DataTable dt = new DataTable();
                da.Fill(dt);
                return dt;
            }
        }
        #endregion User_Insert(UserInfo data)
        #region[User_GetByIDl]
        public DataTable User_GetByID(string ID)
        {
            using (SqlCommand cmd = new SqlCommand("sp_User_GetByIDl", GetConnection()))
            {
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add(new SqlParameter("@ID",ID));
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                DataTable dt = new DataTable();
                da.Fill(dt);
                return dt;
            }
        }
        #endregion User_Insert(UserInfo data)
        #region[User_GetByTopl]
        public DataTable User_GetByTop(string Top,string Where,string Order)
        {
            using (SqlCommand cmd = new SqlCommand("sp_User_GetByTop", GetConnection()))
            {
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add(new SqlParameter("@Top", Top));
                cmd.Parameters.Add(new SqlParameter("@Where", Where));
                cmd.Parameters.Add(new SqlParameter("@Order", Order));
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                DataTable dt = new DataTable();
                da.Fill(dt);
                return dt;
            }
        }
        #endregion User_Insert(UserInfo data)
    }
}
